#include "client.h"

int putsFunc(int sockfd,const char* filename){
    int iferror;
    recv(sockfd,&iferror,sizeof(int),0);
    if(iferror==-1){
        printf("上传失败\n");
        return -1;
    }
    printf("loading..........\n");
    train_t t_file;
    bzero(&t_file,sizeof(t_file));
    int fd=open(filename,O_RDWR);
    struct stat statbuf;//可以获取文件属性信息
    fstat(fd,&statbuf);
    printf("总大小：%ld\n",statbuf.st_size);
    while(1){
        bzero(&t_file,sizeof(t_file));
        ssize_t sret=read(fd,t_file.data,sizeof(t_file.data));
        printf("filedata:%s\n",t_file.data);
        if(sret==0){
            printf("上传结束\n");
            break;
        }
        t_file.length=sret;
       // sleep(200);
        sret=send(sockfd,&t_file,sizeof(t_file.length)+t_file.length,MSG_NOSIGNAL);
        printf("已上传 %ld\n",sret);
       // fflush(stdout);
    }
    t_file.length=0;
    send(sockfd,&t_file,sizeof(t_file.length),MSG_NOSIGNAL);
    close(fd);
    return 0;

}
